package com.lelefly.base.utils;

import java.lang.reflect.Field;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;

public class Paramutils {

	public static void requestParamsToModel(HttpServletRequest request,
			Object model) throws IllegalArgumentException,
			IllegalAccessException {

		Field[] fields = model.getClass().getDeclaredFields();
		
		for (Field field : fields) {
			
			if (StringUtils.isNotEmpty(request.getParameter(field.getName()))) {
				
				field.set(model, request.getParameter(field.getName()));
			}
		}

	}
}
